import React, { Component } from 'react'
import store from '../store'
import axios from 'axios'


export default class Home extends Component {
    changeCount = () => {
        // store.dispatch({ type: "CHANGE_COUNT", num: 100 })

        // store.dispatch   增强过后   
        store.dispatch((next) => {
            axios.get("https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata").then(res => {
                // next  没有增强过以后的dispatch
                // store.dispatch   
                next({ type: "INIT", res: res.data.message })
            })
        })

        // 回调地狱
        // store.dispatch(() => {
        //     axios.get("https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata").then(res => {
        //         // next  没有增强过以后的dispatch
        //         // store.dispatch   
        //         store.dispatch(axios.get("https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata").then(res => {
        //             // next  没有增强过以后的dispatch
        //             // store.dispatch   
        //             store.dispatch(axios.get((next) => {
        //                 axios.get("https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata").then(res => {
        //                     // next  没有增强过以后的dispatch
        //                     // store.dispatch   
        //                     next({ type: "INIT", res: res.data.message })
        //                 })
        //             }))
        //         }))
        //     })
        // })

        // *

    }
    render() {
        return (
            <div>
                <h3>
                    我是Home -- { store.getState().count }
                </h3>
                <button onClick={() => {
                    this.changeCount()
                }}>修改count</button>

                <ul>
                    {
                        store.getState().list.map((item, index) => {
                            return <li key = { index }>
                                { item.image_src }
                            </li>
                        })
                    }
                </ul>
            </div>
        )
    }
}
